home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 (Walnut Creek) / Aminet - June 1993 [Walnut Creek].iso / aminet / comm / fido / xprfts072.lzh / lotek.c < prev    next >
C/C++ Source or Header  |  1992-11-24  |  6KB  |  218 lines

  1. /*
  2.     $Header: Welmat:src/Welmat/xprfts/RCS/lotek.c,v 1.2 92/11/24 23:40:31 rwm Exp Locker: rwm $
  3.  
  4.     Perform a Lotek/DietIFNA session
  5.  
  6.     Copyright (C) 1988,1989,1990 Michael Richardson
  7.     Copyright (C) 1992 Russell McOrmond
  8.  
  9.     This program is free software; you can redistribute it and/or modify
  10.     it under the terms of the GNU General Public License as published by
  11.     the Free Software Foundation; either version 2 of the License, or
  12.     (at your option) any later version.
  13.  
  14.     This program is distributed in the hope that it will be useful,
  15.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.     GNU General Public License for more details.
  18.  
  19.     You should have received a copy of the GNU General Public License
  20.     along with this program; if not, write to the Free Software
  21.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  
  23. */
  24.  
  25.  
  26. #ifdef RCSID
  27. static char RCSid[]="$Id: lotek.c,v 1.2 92/11/24 23:40:31 rwm Exp Locker: rwm $\n";
  28. #endif
  29.  
  30. #include <proto/all.h>
  31. #include <exec/types.h>
  32. #include <exec/memory.h>
  33. #include <ctype.h>
  34. #include <stdio.h>
  35. #include <stdlib.h>
  36. #include <string.h>
  37. #include "xproto.h"
  38. #include "xmodem.h"
  39. #include "xprfts.h"
  40.  
  41. struct ExecBase *SysBase=(struct ExecBase *)4l;
  42.  
  43. /* Main file transmission routine; called by comm program */
  44. long  __saveds XProtocolSend(struct XPR_IO *io) {
  45.   struct Vars *v;
  46.   int state;
  47.   char filename[256];
  48.  
  49.   /* Perform common setup and initializations */
  50.   if (!(v = setup(io)))  return XPRS_FAILURE;
  51.  
  52. #ifdef KDEBUG
  53.   KPrintF("7%lc C%lc O%lc I%lc P%lc S%lc B%lc A%lc N%lc W%lc F%lc M%lc D:%ld\n",
  54.    v->option_7,v->option_c,v->option_o,v->option_i,v->option_p,
  55.    v->option_s,v->option_b,v->option_a,v->option_n,v->option_w,v->option_f,
  56.    v->option_m, v->debug);
  57. #endif
  58.  
  59.   (void) xpr_sread(v,filename,255,1000000);
  60.  
  61.   state=sendXFiles(v);
  62.  
  63.   if(state==NODCD) goto ret1;
  64.   else if(state!=OK) {
  65.     updmsg(v,"Couldn't indicate end of outbound file attaches!");
  66.     goto ret1;
  67.   } else 
  68.     updmsg(v,"End of outbound file attaches.");
  69.  
  70.   if(v->option_p=='N') {
  71.     updmsg(v,"Not picking up.");
  72.     goto ret1;
  73.   }
  74.   xpr_sflush(&v->io);
  75.  
  76. /*
  77.  |-----+----------+-------------------------+-------------------------+-----|
  78.  | R3* | RecMail  |                         | (XMODEM rec packet XR0) | R4  |
  79.  |-----+----------+-------------------------+-------------------------+-----|
  80.  | R4  | XRecEnd  | 1 XMODEM successful     | delay 1 second          | R5  |
  81.  |     |          |                         |   flush input           |     |
  82.  |     |          | 2 XMODEM failed         | hang up, rept mail fail | exit|
  83.  */
  84.  
  85.   updmsg(v,"Exchanging roles");
  86.   filename[0]='\0';
  87.   if((state=receiveXFile(filename,v,FALSE))==OK) {
  88.     updstatus(v,filename,XPRS_SUCCESS);
  89.     while(state==OK) {
  90.       filename[0]='\0';
  91.       state = receiveXFile(filename,v,TRUE);
  92.       updstatus(v,filename,(state==OK) ? XPRS_SUCCESS : XPRS_FAILURE);
  93.     }
  94.   }
  95.  
  96.   ret1:
  97.   SPrintF(v->scratch,"R2: End of outbound Lotek/DietIFNA session.(%ld)\n",state);
  98.   updmsg(v,v->scratch);
  99.  
  100.   /* Clean up and return */
  101.   FreeMem(v,(long)sizeof(struct Vars));
  102.   return ((state==ERROR) ? XPRS_FAILURE : XPRS_SUCCESS );
  103. }
  104.  
  105.  
  106. /* Main protocol for inbound calls */
  107. long __saveds XProtocolReceive(struct XPR_IO *io) {
  108.   struct Vars *v;
  109.   int state;
  110.   char filename[256];
  111.  
  112.   /* Perform common setup and initializations */
  113.   if (!(v = setup(io))) return XPRS_FAILURE;
  114.  
  115. #ifdef KDEBUG
  116.   KPrintF("7%lc C%lc O%lc I%lc P%lc S%lc B%lc A%lc N%lc W%lc F%lc M%lc D:%ld\n",
  117.    v->option_7,v->option_c,v->option_o,v->option_i,v->option_p,
  118.    v->option_s,v->option_b,v->option_a,v->option_n,v->option_w,v->option_f,
  119.    v->option_m, v->debug);
  120. #endif
  121.  
  122.   (void) xpr_sread(v,filename,255,1000000);
  123.  
  124. /*
  125.  |-----+----------+-------------------------+-------------------------+-----|
  126.  | R3* | RecMail  |                         | (XMODEM rec packet XR0) | R4  |
  127.  |-----+----------+-------------------------+-------------------------+-----|
  128.  | R4  | XRecEnd  | 1 XMODEM successful     | delay 1 second          | R5  |
  129.  |     |          |                         |   flush input           |     |
  130.  |     |          | 2 XMODEM failed         | hang up, rept mail fail | exit|
  131.  */
  132.  
  133.   updmsg(v,"Mail bundles");
  134.   filename[0]='\0';
  135.   if((state=receiveXFile(filename,v,FALSE))!=OK && state!=GOTEOT) {
  136.     updstatus(v,filename,XPRS_FAILURE);
  137.     goto ret2;
  138.   }
  139.   updstatus(v,filename,XPRS_SUCCESS);
  140.   filename[0]='\0';
  141.  
  142.   if (state!=GOTEOT) {
  143.     updmsg(v,"Inbound File attaches");
  144.     while((state=receiveXFile(filename,v,TRUE))==OK) {
  145.       updstatus(v,filename,XPRS_SUCCESS);
  146.       filename[0]='\0';
  147.     }
  148.     if(state!=GOTEOT) {
  149.       updstatus(v,filename,XPRS_FAILURE);
  150.       goto ret2;
  151.     }
  152.     updstatus(v,filename,XPRS_SUCCESS);
  153.   }
  154.   updmsg(v,"End of inbound file attaches");
  155.   updmsg(v,"Turn around and send");
  156.  
  157.   state=sendXFiles(v);
  158.  ret2:
  159.  
  160.   SPrintF(v->scratch,"R2: End of inbound Lotek/DietIFNA session.(%ld)\n",state);
  161.   updmsg(v,v->scratch);
  162.  
  163.   /* Clean up and return */
  164.   FreeMem(v,(long)sizeof(struct Vars));
  165.   return ((state==ERROR) ? XPRS_FAILURE : XPRS_SUCCESS);
  166. }
  167.  
  168. int AllocWindowX(struct WindowX *WindowXBuff)
  169. {
  170.   int i;
  171.  
  172.   NewList(&WindowXBuff->wx_blocks);
  173.   NewList(&WindowXBuff->wx_freeblocks);
  174.   if((WindowXBuff->blockBuffer=AllocMem(sizeof(block)*(MAXXWINDOW+1),
  175.            MEMF_PUBLIC|MEMF_CLEAR))==NULL)
  176.             return(FALSE);
  177.  
  178.   for(i=0; i<=(MAXXWINDOW); i++) {
  179.     AddTail(&WindowXBuff->wx_freeblocks,(void *)((long)(WindowXBuff->blockBuffer)
  180.                          +(i*sizeof(block))));
  181.   }
  182.   return(TRUE);
  183. }
  184.  
  185. void FreeWindowX(struct WindowX *WindowXBuff)
  186. {
  187.   FreeMem(WindowXBuff->blockBuffer,sizeof(block)*(MAXXWINDOW+1));
  188. }
  189.  
  190. void AckNak(struct Vars *v,int SeaLink,int blocknum,char AckNak)
  191. {
  192.   char *c;
  193.   char temp[100];
  194.  
  195.   c="Unknown";
  196.   switch(AckNak) {
  197.     case ACK:
  198.       c="S:ACK";
  199.       break;
  200.     case NAK:
  201.       c="S:NAK";
  202.       break;
  203.     case CNAK:
  204.       c="S:CNAK";
  205.       break;
  206.   }
  207.   temp[0]=AckNak;
  208.   xpr_swrite(&v->io,temp,1);
  209.   if(SeaLink) {
  210.     temp[0]=blocknum&0xff;
  211.     temp[1]=(~blocknum)&0xff;
  212.     xpr_swrite(&v->io,temp,2);
  213.     SPrintF(temp,"%s*",c);
  214.     updmsg(v,temp);
  215.   } else
  216.     updmsg(v,c);
  217. }
  218.